package cn.bird.storm.validated.paramcheck.tool;


import cn.bird.storm.validated.paramcheck.ParamCheckComponent;
import cn.bird.storm.validated.paramcheck.model.customize.Customize;
import cn.bird.storm.validated.paramcheck.model.least.LeastOneNotEmpty;
import cn.bird.storm.validated.paramcheck.model.notempty.NotEmpty;
import cn.bird.storm.validated.paramcheck.model.stringscope.StringScope;
import lombok.Data;

import java.util.Objects;

public class Main {

    public static void main(String[] args) {
//        ParamCheckComponent.toCheck(b ->
//                b.notEmpty("手机号", "e54")
//                        .notEmpty("姓名", "")
//                        .notEmpty("地址", "大连地址")
//                        .least("connect", "联系电话", "")
//                        .least("connect", "邮箱", "")
//                        .least("age", "年龄", null)
//                        .least("age", "出生年月", "44")
//                        .customize("是这样的！", "傻?？", Main::passTest)
//                        .stringScope("季度", "e3", Lists.newArrayList("e1", "e2", "e3"))
//                        .stringScope("微信类型", "123", "123", "345")
//        );

        Person person = new Person();
        person.setName("合适");
        person.setScope("");
        person.setAge("12");
        person.setLeast3("nihc");
        person.setCustomize("你真的聪明！");
        person.setScope2("e2");
        ParamCheckComponent.customizeTest("passTest", Main::passTest);
        ParamCheckComponent.check(person);
    }

    public static boolean passTest(Object str){
        if (Objects.isNull(str)) {
            return false;
        }
        String s = (String) str;
        //不包含傻，就通过
        return !s.contains("傻");
    }



    @Data
    public static class Person{

        @NotEmpty(value = "姓名", organizes = "add")
        private String name;
        @NotEmpty("年龄")
        private String age;
        @NotEmpty(value = "联系方式", organizes = "update")
        private String phone;
        @LeastOneNotEmpty(value = "least1", group = "1",organizes = "update")
        private String least1;
        @LeastOneNotEmpty(value = "least2", group = "1", organizes = "update")
        private String least2;
        @NotEmpty("least3")
        @LeastOneNotEmpty(value = "least3", group = "2")
        private String least3;
        @LeastOneNotEmpty(value = "least4", group = "2")
        private String least4;
        @StringScope(value = "季度", stringScope = {"e1", "e2", "e3", ""})
        private String scope;
        @NotEmpty("季度2")
        @StringScope(value = "季度2", stringScope = {"e1", "e2", "e3"})
        private String scope2;
        @Customize(value = "是这样的！", customize = "passTest")
        private String customize;

    }

}
